﻿@{
    ViewBag.Title = "ReportPublish";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@using Agro.Web;
@section head {
    @if (false)
    {<script src="~/Scripts/jquery-1.6.4-vsdoc.js" type="text/javascript"></script>}
    <link href="@Url.Content("~/Content/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.ztree.all-3.0.min.js")" type="text/javascript"></script>
    @Html.Partial("_JqGrid")
    <script language="javascript" type="text/javascript">
        var gridId = "#tableId";
        var curSelectNode = null;
        var reportid = "";
        var cycle = "";
        var CurrOrganizationID = '@ViewBag.CurrOrganizationID'; //当前登录用户所在的部门，主要用于在grid中，将当前单位的记录显示醒目色。
        $(document).ready(function () {
            loadReportTree();
            $("#ReportMenu div:eq(0)").trigger("click");
            //先click后加载grid的原因是，先给report赋值。
            funGridInit();
        });

        function Search() {
            //查询
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }

        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 101,
                width: $("#divGridContainer").width() - 2,
                url: '/SystemManage/SubmitInfo/GetReportStateList',
                autowidth: false,
                rowNum: 40,
                datatype: "json",
                sortname: 'SubmitInfo_State',
                sortorder: 'asc',
                colModel: [
                { label: '单位编号', name: 'Organization_Code', width: 100, sortable: false },
                { label: '单位名称', name: 'Organization_Name', width: 150, sortable: false },
                { label: '报表名称', name: 'Report_Name', width: 200, sortable: false },
                { label: '报表类型', name: 'Report_Cycle', width: 50, align: "center", sortable: false, formatter: 'select', editoptions: { value: "01:月报;02:季报;03:年报"} },
                { label: '上报状态', name: 'SubmitInfo_State', width: 70, align: "center", sortable: false, formatter: 'select', editoptions: { value: "0:未上报;1:已上报;2:已汇总"} },
                { label: '创建日期', name: 'SubmitInfo_CreateDate', width: 100, align: "center", sortable: false },
                { label: '截止上报日期', name: 'SubmitInfo_EndDate', width: 100, align: "center", sortable: false },
                { label: '延迟上报日期', name: 'SubmitInfo_LazyDate', width: 100, align: "center", sortable: false },
                { label: '制表人', name: 'SubmitInfo_CreatorName', width: 70, align: "center", sortable: false },
                { label: '报出日期', name: 'SubmitInfo_SubmitDate', width: 100, align: "center", sortable: false },
                { label: '数据来源', name: 'SubmitInfo_Sjly', width: 100, align: "center", sortable: false },
                { name: 'SubmitInfo_ID', hidden: true },
                { name: 'SubmitInfo_Year', hidden: true },
                { name: 'SubmitInfo_Month', hidden: true },
                { name: 'SubmitInfo_Day', hidden: true },
                { name: 'SubmitInfo_ReportID', hidden: true },
                { name: 'Organization_ID', hidden: true }
   	            ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                },
                ondblClickRow: function (rowid) {

                },
                beforeRequest: function (d) {
                    if (reportid == null)
                        return false;
                    var data = { 'reportid': reportid, 'queryData': $('#queryForm').serialize() };
                    $(gridId).jqGrid('setGridParam', { postData: data });
                },
                gridComplete: function () {
                    var _rownum = $(gridId).getDataIDs().length;
                    for (var i = 1; i <= _rownum; i++) {
                        var cycle = $(gridId).getCell(i, "SubmitInfo_Cycle");
                        var str_year = $(gridId).getCell(i, "SubmitInfo_Year");
                        var str_month = $(gridId).getCell(i, "SubmitInfo_Month");
                        var str_day = $(gridId).getCell(i, "SubmitInfo_Day");
                        var str_EndDate = $(gridId).getCell(i, "SubmitInfo_EndDate");
                        var str_LazyDate = $(gridId).getCell(i, "SubmitInfo_LazyDate");
                        //设置已上报状态为#CC6600
                        var State = $(gridId).getCell(i, "SubmitInfo_State");
                        bkcolor = "#FFFF00"; //橘红色F7983A  
                        if (State == "0") {
                            var celldata = $(gridId).getCell(i, "SubmitInfo_State");
                            $(gridId).setCell(i, "SubmitInfo_State", celldata, { background: bkcolor });
                            //                            var rowdata = $(gridId).getRowData(i);
                            //                            $(gridId).setRowData(i, rowdata, { background: bkcolor });

                        }

                        //将已经延迟上报的变色为#FFCC00
                        if (str_EndDate != str_LazyDate) {
                            bkcolor = "#FFCC00"; //橘红色F7983A  
                            $(gridId).setCell(i, "SubmitInfo_LazyDate", str_LazyDate, { background: bkcolor });
                        }
                    }
                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
        }

        function loadReportTree() {

            $("#ReportMenu").html("");
            $.ajax({
                async: false,
                type: "POST",
                url: "/SystemManage/SubmitInfo/GetReportNameList",
                success: function (msg) {
                    var data = eval(msg);
                    $.each(data, function (index, d) {

                        var imgurl = d.Report_Image;
                        if (imgurl == null || imgurl == "null" || imgurl == undefined) {
                            imgurl = "/Content/32/125.png";
                        }
                        $("#ReportMenu").append("<div cycle='" + d.Report_Cycle + "' url='" + d.Report_ID + "' ><table><tr><td valign='top'><img src='" + imgurl + "'/></td><td >" + d.Report_Name + "</td></tr></table></div>");

                    })

                    $("#ReportMenu div").hover(
                      function () {

                          $(this).addClass("navHover");

                      },
                      function () {
                          if ($(this).attr("isselect") == "true") {

                          }
                          else {
                              $(this).removeClass("navHover");

                          }
                      }
                    );
                    $("#ReportMenu div").click(function () {
                        $("#ReportMenu div").attr("isselect", false);
                        $("#ReportMenu div").removeClass("navHover");
                        $(this).attr("isselect", true);
                        $(this).addClass("navHover");
                        reportid = $(this).attr("url");
                        cycle = $(this).attr("cycle");
                        loaddefautdate();
                        Search();

                    });


                }
            });

        }

        function loaddefautdate() {
            var year, month, season, nb_year, jb_year, jb_season, yb_year, yb_month;
            var myDate = new Date();
            year = myDate.getFullYear();
            month = myDate.getMonth() + 1; //月份默认从0开始
            season = Math.ceil(month / 3);
            $("#ListYear").html("");
            $("#ListMonth").html("");
            $("#OrganizationName").val("");
            $("#SubmitInfo_State").val("");
            
            //默认不是示月份
            $("#ListMonth").hide();
            $("#CXMonth").hide();
            

            //先给年份默认值 
            var startyear = myDate.getFullYear() - 5;
            var endyear = myDate.getFullYear() + 2
            for (var i = startyear; i <= endyear; i++) {
                var option = $("<option>").text(i + "年").val(i);
                $("#ListYear").append(option);
            }


            //根据报表期间默认年份和月份
            if (cycle == "01") {
                
                $("#ListMonth").show();
                $("#CXMonth").show();
                $("#CXMonth").html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;查询月份:");
                for (var i = 1; i < 13; i++) {
                    var option = $("<option>").text(i + "月").val(i < 10 ? ('0' + i) : i);
                    $("#ListMonth").append(option);
                }

                if (month == 1) {
                    yb_year = year - 1;
                    yb_month = 12;
                }
                else {
                    yb_year = year;
                    yb_month = month - 1;
                    if (yb_month < 10)
                        yb_month = '0' + yb_month;
                }
                $("#ListYear").val(yb_year);
                $("#ListMonth").val(yb_month);


            } else if (cycle == "02") {
                
                $("#ListMonth").show();
                $("#CXMonth").show();
                $("#CXMonth").html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;查询季度:");
                for (var i = 1; i<=4; i++) {
                    var option = $("<option>").text("第" + (i) + "季度").val("0"+i)
                    $("#ListMonth").append(option);
                }

                if (season == 1) {
                    jb_year = year - 1;
                    jb_season = '04';
                }
                else {
                    jb_year = year;
                    jb_season ="0"+( season - 1);
                }
                $("#ListYear").val(jb_year);
                $("#ListMonth").val(jb_season);

            }
            else {
               
                nb_year = year - 1;
                 $("#ListYear").val(nb_year);
            }
        }

    </script>
}
<!--头部导航,不用时可以去掉-->
<div class="ui-layout-north">
    <div id="headertitle">
    </div>
    <div class="buttonlist" style="float: right; height: 34px; line-height: 36px; margin-right: 20px;">
    </div>
</div>
<!--左侧导航，不用时直接去掉-->
<div class="ui-layout-west  navPanelMini ui-layout-pane ui-layout-pane-west ui-layout-pane-hover ui-layout-pane-west-hover ui-layout-pane-open-hover ui-layout-pane-west-open-hover"
    id="ReportMenu" style="font: 12px/1.6em 'Microsoft Yahei', Tahoma, sans-serif">
</div>
<!--主窗体，页面都需要的div-->
<div id="divGridContainer" class="ui-layout-center" style="overflow: hidden;">
    <div id="divPageSearsh" class="ui-widget-background my-pageSearsh">
        <form action="#" id="queryForm" method="post">
        <div class="l-left">
            <div class='l-col' style="padding-left: 5px;">
                <label for="CXYear" id="CXYear">
                    查询年度:</label>
                <select id="ListYear" name="ListYear" style="width: 100px;">
                </select>
                
                <label for="CXMonth" id="CXMonth">
                    &nbsp;&nbsp;&nbsp;&nbsp;查询月份:</label>
                <select id="ListMonth" name="ListMonth" style="width: 100px;">
                </select>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <label for="SBZT">
                    上报状态:</label>
                <select id="SubmitInfo_State" name="SubmitInfo_State" style="width: 100px;">
                    <option value=""></option>
                    <option value="0">未上报</option>
                    <option value="1">已上报</option>
                </select>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <label for="DWMC">
                    单位名称:</label>
                <input id="OrganizationName" name="OrganizationName" style="width: 100px;" type="text"
                    value="" />
                <input id="hiddenText" type="text" style="display: none" /><!--添加该隐藏框是为了防止，当页面只有一个TextBox时，回车页面自动刷新的事情-->
                <a onclick="Search()" class="button green"><span class="icon-botton" style="background: url('/Content/16/search.png') no-repeat scroll 0px 4px;">
                </span>查询</a>
            </div>
        </div>
        </form>
    </div>
    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
